﻿#include "baserequester.h"

BaseRequester::BaseRequester(QObject *parent) : QObject(parent)
{
    _timer = new QTimer(this);
    connect(_timer, &QTimer::timeout, this, &BaseRequester::keepLive);
}

bool BaseRequester::request(QByteArray data, QByteArray &rec)
{
    QByteArray arr=QByteArray::fromHex("from RequesterBase");
    return true;
}

bool BaseRequester::requestNoReply(QByteArray data)
{
    return true;
}

void BaseRequester::setKeepLiveData(QByteArray arr, int intervalMs)
{
    _keepLiveData = arr;
    _timer->setInterval(intervalMs);
}

void BaseRequester::startKeepLive()
{
    _timer->start();
}

void BaseRequester::stopKeepLive()
{
    _timer->stop();
}

void BaseRequester::keepLive()
{
    QMutexLocker locker(&_mutex);
    QByteArray rec;
    if (!this->request(_keepLiveData, rec))
    {
        qDebug() << __FUNCTION__ << __LINE__ << "keep live failed!";
    }
}
